The AdminController provides administrative functionality for reviewing, approving, and rejecting product return requests. It is restricted to users with Grado 1 (Administrator) access level.Source:controllers/AdminController.phpAccess Control: Grado 1 only (Administrator)Dependencies:
Models/DevolucionModel.php - Return data access and processing
Models/ConsultaModel.php - History queries
Models/NotificacionModel.php - Notification system (optional)
All methods in this controller require Grado 1 (Administrator) privileges. Unauthorized access attempts are automatically redirected to the login page.
Source Code:
public function __construct() { if (session_status() === PHP_SESSION_NONE) session_start(); // Verificar autenticación y permisos (Solo Grado 1 - Administrador) if (!isset($_SESSION['logged_in']) || $_SESSION['grado'] != 1) { header('Location: index.php?url=auth/index'); exit; } $this->model = new DevolucionModel(); $this->consultaModel = new ConsultaModel();}
Administrator full name (fallback if ‘user’ not set)
Error Handling:All exceptions are caught, logged to PHP error log, and user is redirected with error message.Source Code:
public function revisar() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { // Validar datos recibidos $id = intval($_POST['id_devolucion'] ?? 0); $accion = trim($_POST['accion'] ?? ''); $codigo = trim($_POST['codigo_admin'] ?? ''); $obs = trim($_POST['observacion_admin'] ?? ''); $revisor = $_SESSION['user'] ?? $_SESSION['nombre']; // Validaciones if ($id <= 0) { throw new Exception('ID de devolución inválido'); } if (!in_array($accion, ['aprobado', 'rechazado'])) { throw new Exception('Acción inválida. Debe ser "aprobado" o "rechazado"'); } if (empty($codigo)) { throw new Exception('El código de autorización es obligatorio'); } if (empty($obs)) { throw new Exception('Las observaciones son obligatorias'); } // Procesar la revisión $resultado = $this->model->procesarRevision($id, $accion, $codigo, $obs, $revisor); if ($resultado) { // Intentar crear notificación (opcional, si existe el modelo) $this->crearNotificacion($id, $accion, $obs); // Redirigir con mensaje de éxito header('Location: index.php?url=admin/index&msg=success'); } else { throw new Exception('Error al procesar la revisión en la base de datos'); } } catch (Exception $e) { // Log del error error_log("Error en AdminController::revisar - " . $e->getMessage()); // Redirigir con mensaje de error header('Location: index.php?url=admin/index&msg=error'); } exit; } else { // Si no es POST, redirigir al panel header('Location: index.php?url=admin/index'); exit; }}